package xyz.hzxiao.client;

import io.netty.channel.Channel;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;

/**
 * websocket客户端通道
 *
 * @author ：FuXx
 * @className : cn.miying.server.client.ClientChannel
 * @since ：2024/10/10
 */
public class ClientChannelHolder {

    /**
     * 在线客户端
     */
    private static final Map<String, String> ONLINE_MAP = new ConcurrentSkipListMap<>();

    /**
     * @param channel WebSocket通道
     */
    public static void addClient(Channel channel, String roomNo) {
        ONLINE_MAP.put(channel.id().asLongText(), roomNo);
    }

    /**
     * @return 房间列表
     */
    public static Collection<String> getOnlineList() {
        return ONLINE_MAP.keySet();
    }

    /**
     * @param sessionId 会话id
     */
    public static void removeClient(String sessionId) {
        ONLINE_MAP.remove(sessionId);
    }
}
